import NetConfig from "../NetConfig";
import TSMap from "../../math/TSMap";
let FLAG = "$"
export default class ServiceInfo{

    private connectType:string = NetConfig.WEB_SOCKET;

    private serviceID:string = "";

    private token:string;
    //发送协议和返回协议的映射表，有些以协议发送和返回时相同的。
    // 如果发送协议和返回协议号相同。这个表自动生成。
    protected protocolMap : TSMap = new TSMap();

    constructor(cType:string,serviceID:string){
        this.connectType = cType;
        this.serviceID = serviceID;
    }


    getConnectType(){
        return this.connectType;
    }

    getUrl(){
        if(this.serviceID.indexOf(FLAG) >= 0){
            return this.serviceID.split(FLAG)[0];
        }else{
            return this.serviceID;
        }
    }

    getPort(){
        if(this.serviceID.indexOf(FLAG) >= 0){
            return parseInt(this.serviceID.split(FLAG)[1]);
        }else{
            return 0;
        }     
    }

    setToken(k){
        this.token = k;
    }

    getToken(){
        return this.token;
    }

    setProtocolMap(map){
        if(map){
            this.protocolMap = map;
        }  
    }

    getProtocalMap(){
        return this.protocolMap;
    }


}
